package com.itheima.article.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.itheima.article.pojo.ApArticleConfig;
import com.itheima.article.mapper.ApArticleConfigMapper;
import com.itheima.article.service.ApArticleConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @description <p>APP已发布文章配置 业务实现</p>
 *
 * @version 1.0
 * @package com.itheima.article.service.impl
 */
@Service
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {

    /**
     * 文章上下架同步
     *
     * @param value
     */
    @Override
    public void upOrDown(String value) {
        JSONObject jsonObject = JSON.parseObject(value);
        Long articleId = jsonObject.getLong("articleId");
        Integer enable = jsonObject.getInteger("enable");
        ApArticleConfig apArticleConfig = new ApArticleConfig();
        apArticleConfig.setId(articleId);
        //同步文章上下架状态
        apArticleConfig.setIsDown(enable==0?1:0);
        updateById(apArticleConfig);
    }
}
